package com.han.mockgenerator;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.NamingException;

import com.han.bom.MultipleChoice;
import com.han.bom.Professor;
import com.han.bom.Question;
import com.han.bom.Student;
import com.han.bom.TrueOrFalse;
import com.han.dao.concrete.product.AnswerDAO;
import com.han.dao.concrete.product.QuestionDAO;
import com.han.dao.concrete.product.UserDAO;

public class DataFactory {

	private static final String password = "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92";
	
	public static void generateData() throws ClassNotFoundException, SQLException, NamingException{
		
		ArrayList<String> choices = new ArrayList<String>();
		
		for(int i=0;i<4;i++){
			choices.add("Choice#"+(i+1));
		}
		
		UserDAO userdao = new UserDAO();
		QuestionDAO questiondao = new QuestionDAO();
		AnswerDAO answerdao = new AnswerDAO();
		
		for(int i=0;i<2;i++){

			int userID1 = userdao.retrieveMaxUserID();
			
			Professor professor = new Professor(userID1);
			professor.setFirstName("professor");
			professor.setLastName("rofessor");
			professor.setUsername("professor"+userID1);
			professor.setPassword(password);
			
			userdao.insertUser(professor);
			
			for(int j=0;j<10;j++){
				int userID2 = userdao.retrieveMaxUserID();
				
				Student student = new Student(userID2);
				student.setFirstName("student");
				student.setLastName("tudent");
				student.setUsername("student"+userID2);
				student.setPassword(password);
				
				userdao.insertUser(student);
				userdao.addStudentToProfessor(student.getUserID(), professor.getUserID());
			}
			
			for(int j=i*20;j<(i*20)+20;j++){
				
				Question q = null;
				
				if(j%2==0){ //tf
					if(j%4==0){
						q = new TrueOrFalse(professor.getUserID()+" TF "+j, "True");
					}
					else{
						q = new TrueOrFalse(professor.getUserID()+" TF "+j, "False");
					}
					q.setQuestionID("Q"+(questiondao.retrieveMaxQuestionID())+"TF");
				}
				else{
					q = new MultipleChoice(professor.getUserID()+" MC "+j, choices.get(0), choices);
					q.setQuestionID("Q"+(questiondao.retrieveMaxQuestionID())+"MC");
				}
				
				q.setCategory("Test");
				
				questiondao.insertQuestion(q);
				
				answerdao.addAnswerToQuestion(q);
				
			}
		}
		
		
		
	}
	
}
